package org.i1510.common.utils.mail;

import java.util.Properties;

import org.junit.Test;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;



public class SpringMailTest {
	@Test
	public void sendMain() {
		
		// 发送邮件
		try {
			JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
			// 设定mail server
			senderImpl.setHost("smtp.163.com");
			senderImpl.setPort(25);
			
			// 建立邮件消息
			SimpleMailMessage simpleMessage = new SimpleMailMessage();
			// 设置收件人，寄件人 用数组发送多个邮件
			// String[] array = new String[] {"sun111@163.com","sun222@sohu.com"};
			// mailMessage.setTo(array);
			simpleMessage.setTo("wuhengbo123@163.com");
			simpleMessage.setFrom("kenshinbo@163.com");
			simpleMessage.setSubject(" 测试简单文本邮件发送！ ");
			simpleMessage.setText(" 测试我的简单邮件发送机制！！ ");

			senderImpl.setUsername("kenshinbo@163.com"); // 根据自己的情况,设置username
			senderImpl.setPassword("sds1"); // 根据自己的情况, 设置password

			Properties prop = new Properties();
			prop.put("mail.smtp.auth", "true"); // 将这个参数设为true，让服务器进行认证,认证用户名和密码是否正确
			prop.put("mail.smtp.timeout", "25000");
			
			senderImpl.setJavaMailProperties(prop);
			senderImpl.send(simpleMessage);

		} catch (Exception e) {
			// TODO: handle exception
		}
		
		System.out.println(" 邮件发送成功.. ");

	}
}
